#include<iostream>
#include<algorithm>
#include<iterator>
#include<ctime>
using namespace std;

int* Unique(int* start, int* end)
{
    int* q = start;
    int* p = q++;
    
    for (; q != end; ++q)
    {
        if (*p != *q)
        {
            *++p = *q;
        }
    }
    
    return ++p;
}

class RandMod
{
public:
    RandMod(int value)
    : m_nMask(value){}
    int operator()(void)
    {
        return rand() % m_nMask;
    }
private:
    int m_nMask;
};

int main(void)
{
    srand((unsigned int)time(NULL));
    
    const int SIZE = 15;
    int array[SIZE];
    
    generate(array, array + SIZE, RandMod(20));
    
    sort(array, array + SIZE);
    copy(array, array + SIZE, ostream_iterator<int>(cout, " "));
    cout<<endl;
    
    int* pos = Unique(array, array + SIZE);
    copy(array, pos, ostream_iterator<int>(cout, " "));
    cout<<endl;
    
    system("pause");
}
